import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:luckin_demo/drawerdemo/rout_page.dart';

void main()  => runApp(

    new MyApp()
);

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        useMaterial3: true,

         primarySwatch: createMaterialColor(Colors.red),
      ),

      home: HomePage(),
      routes: <String,WidgetBuilder>{
    "/a":(BuildContext context) => RoutPage()
    },
    );
  }
}
MaterialColor createMaterialColor(Color color) {
  List strengths = <double>[.05];
  Map<int, Color> swatch = {};
  final int r = color.red, g = color.green, b = color.blue;

  for (int i = 1; i < 10; i++) {
    strengths.add(0.1 * i);
  }
  strengths.forEach((strength) {
    final double ds = 0.5 - strength;
    swatch[(strength * 1000).round()] = Color.fromRGBO(
      r + ((ds < 0 ? r : (255 - r)) * ds).round(),
      g + ((ds < 0 ? g : (255 - g)) * ds).round(),
      b + ((ds < 0 ? b : (255 - b)) * ds).round(),
      1,
    );
  });
  return MaterialColor(color.value, swatch);
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Drawer App'),
        elevation: defaultTargetPlatform == TargetPlatform.android ? 5.0 : 0.0,
      ),
      drawer: Drawer(
        child: ListView(
          children: [
            const UserAccountsDrawerHeader(
                accountName: Text('Panda'),
                accountEmail: Text('997088454@qq.com'),
              currentAccountPicture: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "https://www.itying.com/images/flutter/5.png"),
              ),
              otherAccountsPictures: [
                CircleAvatar(
                  backgroundColor: Colors.white,
                  child: Text("J"),
                )
              ],
            ),
            ListTile(
              title: Text('Page One'),
              trailing: Icon(Icons.arrow_upward),
              onTap: ()=>{
                Navigator.of(context).pop(),
                Navigator.of(context).pushNamed('/a'),

              }
            ),
             ListTile(
              title: Text('Page Two'),
              trailing: Icon(Icons.arrow_upward),
                onTap: ()=>{
                  Navigator.of(context).pop(),
                  Navigator.of(context).push(MaterialPageRoute(builder:
                  (BuildContext context)=> RoutPage(title:'222'))),

                }
              
            ),
            const Divider(indent: 20,endIndent: 50,),
            ListTile(
              title: Text('Close'),
              trailing: Icon(Icons.close),
              onTap: () =>{
                Navigator.of(context).pop()
              },
            ),
          ],
        ),
      ),
      body: Container(
        child: Center(
          child: Text('Home Page'),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {  },
        child: Icon(Icons.add),
      ),
    );
  }
}
